package com.sec.android.app.myfiles.listener;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;

import com.sec.android.app.myfiles.listener.ListenerMgr.LifeCycle;
import com.sec.android.app.myfiles.log.Log;

public class TimeSetBroadcastReceiver extends AbsBroadcastReceiverImp {

    public interface OnTimeSetBroadcast {
        void onTimeSetChanged();
    }

    OnTimeSetBroadcast mProc;

    public TimeSetBroadcastReceiver(Context context, OnTimeSetBroadcast proc, LifeCycle registerTime, LifeCycle unregisterTime) {
        super(context, registerTime, unregisterTime);
        mProc = proc;
    }

    @Override
    IntentFilter getIntentFilter() {
        IntentFilter ret = new IntentFilter();
        ret.addAction(Intent.ACTION_TIMEZONE_CHANGED);
        ret.addAction(Intent.ACTION_TIME_CHANGED);

        return ret;
    }

    @Override
    BroadcastReceiver getBroadcastReceiver() {
        BroadcastReceiver ret = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                if (mProc != null) {
                    Log.d(this, "onReceive() ] action : " + intent.getAction());
                    if (Intent.ACTION_TIMEZONE_CHANGED.equals(intent.getAction()) ||
                            Intent.ACTION_TIME_CHANGED.equals(intent.getAction())) {
                        mProc.onTimeSetChanged();
                    }
                }
            }
        };

        return ret;
    }

}
